//按钮点击事件
import { toast} from 'nc-lightapp-front';
import api from '../../../common/api';
import { promptBox } from 'nc-lightapp-front';
import _ from 'lodash-es';

export default function (props, key) {
    let list = []
    let orderList = []
    for(const key in this.deleteList) {
        if(this.deleteList[key]) {
            list.push(key)
        }
    }
    for(const key in this.orderDeleteList) {
        if(this.orderDeleteList[key]) {
            orderList.push(key)
        }
    }
    this.setState({showNCPopover: false});
    if(key === 'go_reimbursement' || key === 'delete') {
        if ((this.listTabStatus === '0' && list.length === 0) || (this.listTabStatus === '1' && orderList.length === 0)) {
            /* 国际化处理： 必须选择一个*/
            toast({
                color: 'warning',
                content: this.state.multiLang['select_one_row']
            }); 
            return false;
        }
    }
    if (key === 'go_reimbursement') {// 去报销
        this.setState({showTradeType: true})
        const tableAllData = this.invoiceList.map(item =>{
            return item.head.head.rows[0];
        })
        const orderTableAllData = this.orderList.map(item =>{
            return item.head.head.rows[0];
        })
        if(this.listTabStatus === '0'){
            this.setState({checkedList: tableAllData.filter(item=>{
                if(list.includes(item.rowId)){
                    return item
                }
            })})
        }
        if(this.listTabStatus === '1'){
            this.setState({orderCheckedList: orderTableAllData.filter(item=>{
                if(orderList.includes(item.rowId)){
                    return item
                }
            })})
        }
        return;
    }

    if(key === 'delete') {
        const props = this.props;
        promptBox({
            color: 'warning',
            title: this.state.multiLang['delete'],
            content: this.state.multiLang['confirm_delete_select'],
            noFooter: false,
            noCancelBtn: false,
            beSureBtnName: this.state.multiLang['confirm'] /* 国际化处理： 确定*/,
            cancelBtnName: this.state.multiLang['cancel'] /* 国际化处理： 取消*/,
            beSureBtnClick: () => {
                api.deleteWallet({
                    invoicePkList: list
                }).then((res) => {
                    this.loadData(this.state.navTabStatus);
                    this.refreshLeftTicket();
                    toast({
                        color: 'success',
                        content: this.state.multiLang['delete_success']
                    });
                });
            }
        });
    }
    if (key === 'upload_invoice') {
        this.setState({showUploadInvoice: true});
    }
    // 移动到
    if(key=== 'move_wallet') { 
        this.setState({showNCPopover: true});
    }
}
